/*
 *  New Ajaxin Function
 *
 *  Send ajax request
 *
 *  @author     David Lasley, dave -at- dlasley -dot- net
 *  @website    http://code.google.com/p/lightweight-ajax
 *  @package    lightweight-ajax
 *  @license    GPLv3
 *  @version    $Id: ajaxin.js 2 2013-01-24 01:29:52Z dave@dlasley.net $
 */

/*
 *  Ajax
 *
 *  @param  string  url             URL
 *  @param  bool    post            Post?
 *  @param  string  data            Data in urlencoded
 *  @param  obj     returnFunction  Function (httpObj,obj)
 *  @param  bool    async           Async transfer?
 *  @param  string  contentType     Transfer encoding
 *  @param  obj     obj             Object to manipulate in returnFunction
 *
 *  @returns    obj httpObj
 */
function ajaxin(url,post,data,returnFunction,async,contentType,obj){
    try{
        var http;
        if(window.XMLHttpRequest)
            http = new XMLHttpRequest();
        else
            http = new ActiveXObject("Microsoft.XMLHTTP");
        
        http.onreadystatechange = function(){
            try{
                if(http.readyState==4 && http.status==200)
                    return returnFunction(http,obj);
            }catch(ex){
                if(console.log)
                    console.log(ex)
            }
        }
        
        if(!async)
            async = false;
        
        if(post){
            http.open("POST", url, async);
            if(!contentType)
                contentType = "application/x-www-form-urlencoded";
            http.setRequestHeader("Content-type",contentType);
            http.send(data);
        }else{
            http.open("GET", url + '?' + data, async);
            http.send();
        }
        return http;
    }catch(ex){
        if(console.log)
            console.log(ex);
    }
}